#pragma once
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#pragma comment(lib, "SDL_ttf.lib")
#endif

#define COLOR_DEEP 24
#define pi 3.14159265

#include "SDL.h"
#include "SDL_ttf.h"

#include "Position.h"
#include "Color.h"
#include "Texture.h"
#include "Score.h"
#include "TriangularObstacle.h"
#include <map>
#include <sstream>



class SketcherHelper{
	public:	static SketcherHelper* getInstance();

	public: void initializeInstance(int width, int height, Color* backColor, Color* borderColor);
	public: void initializeInstance(int width, int height, Texture* texture, Color* borderColor);
	public: void drawCircle(Position* center, int radiuos, Color* backColor, Color* borderColor);
	public: void drawCircle(Position* center, int radiuos, Texture* backTexture, Color* borderColor);
	public: void drawSquare(Position* position, int width, int height, double angle, Color* backColor, Color* borderColor);
	public: void drawSquare(Position* position, int width, int height, double angle, Texture* backTexture, Color* borderColor);
	public: void drawTriangle(TriangularObstacle * triangle, Color * backGroundColor, Color * lineColor );
	public: void drawLine(Position* fromPosition,Position* toPosition, Color* backColor, Color* borderColor);
	public: double calcDist(Position from,Position to);
	public: double calcAngle(Position from,Position to);
	public: void show();
	public: void endInitialicing();
	public: void clearBackground(Position *p,int width,int height);
	public: void setCoefs(float coeficienteX, float coeficienteY, float coeficiente, int initialX, int initialY, int pixelsHeight);
	public: float getCoeficiente();
	public: Position* getPositionInPixels(Position * position);
	public: Position* getPositionMeasurementUnit(Position * position);
	public: SDL_Surface* createCircleSurface( int radiuos, Texture* backTexture, Color* borderColor);
	public: void drawCircleFromSurface(Position* center, int radiuos,SDL_Surface* surface);
	public: SDL_Surface* createCircleSurface(int radiuos, Color* backColor, Color* borderColor);
	// cache management
	public: bool containsCache(string key);
	public: void addCachedCircle(string key, int radiuos, Texture* backTexture, Color* borderColor, int angle = 0);
	public: void drawCachedCircle(string key, Position* position);

	/*----Sistema de Puntos----*/
	public:
			int text_x,text_y;
			SDL_Rect* aux_rect;
			TTF_Font *aux_font; 
			SDL_Color textColor;
		    void printText(Position* p,Color* c, string text );
	public:TTF_Font *font; 
	/*----Metodos Privados-----*/
	private: void drawSquareFromSurface(SDL_Surface* cuadrado,Position* position,double angle);
	private: void drawPixel(SDL_Surface* screen, Position position, Uint32 pixel);
	private: void drawPixel(SDL_Surface* screen, Position position, Color * color);
	private: Uint32 readPixel(SDL_Surface* source,Position position);
	private: SDL_Surface *SketcherHelper::scaleSurface(SDL_Surface *Surface, Uint16 Width, Uint16 Height);
	private: SDL_Surface *screen;
	private: SDL_Surface *background;
	private: void drawSquareFromSurface(SDL_Surface* cuadrado,double angle);
	private: static SketcherHelper * instance;
	private: map<string, SDL_Surface *> images;
	private: bool initScreen;
	private: float coeficienteX; float coeficienteY; float coeficiente; int initialX; int initialY; int pixelsHeight;
	private: SDL_Surface* loadImage(string filename);
	private: SDL_Surface* clipCircle(SDL_Surface* source);
	private: SDL_Surface* rotateCircle(SDL_Surface* source, float angle);
	private: Uint32 getPixel(SDL_Surface* source, Sint32 x, Sint32 y);
	private: void setPixel(SDL_Surface* target, Sint32 x, Sint32 y, Uint32 pixel);
	public: void clearLine(Position* fromPosition,Position* toPosition);
			void showGameOver(int width, int height, Texture* texture, Color* borderColor);
			// cache management
	private: map<string, SDL_Surface*> cache;
};
